package igou.togogo.controller;

import igou.togogo.bean.EBrand;
import igou.togogo.pojo.EUDataGridResult;
import igou.togogo.pojo.EasyUiStatusResult;
import igou.togogo.pojo.EgouResult;
import igou.togogo.service.IBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    IBrandService iBrandService;

    /*测试ssm框架数据整合 返回json数据*/
    @RequestMapping("/item/{itemId}")
    @ResponseBody
    public EBrand getById(@PathVariable("itemId") int id){
        EBrand eBrand = iBrandService.getById(id);
        return eBrand;
    }

    /*新增品牌*/
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ResponseBody
    public EgouResult addBrand(EBrand brand){
        EgouResult result = iBrandService.addBrand(brand);
        return result;
    }

    //分页查询所有
    @RequestMapping("/list")
    @ResponseBody
    public EUDataGridResult getBrandList(Integer page,Integer rows){
        EUDataGridResult result = iBrandService.getBrandList(page, rows);
        return result;
    }

    //删除品牌 ids
    @RequestMapping("/delete")
    @ResponseBody
    public EasyUiStatusResult delete(String[] ids){
        EasyUiStatusResult result = new EasyUiStatusResult();
        if (ids!=null && ids.length>0){
            try {
                for (int i = 0; i < ids.length; i++) {
                    iBrandService.deleteByPrimaryKey(Integer.parseInt(ids[i]));
                }
                result.setStatus("200");
            }catch (Exception ex){
                result.setStatus("201");
            }

        }
        return result;
    }

}
